package com.cx.mall.user.service.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cx.mall.user.entity.UserInfo;
import com.cx.mall.user.mapper.IUserInfoMapper;
import com.cx.mall.user.service.IUserInfoService;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @version 1.0
 * @Description TODO
 * @Author ke
 * @Since 2025/6/10 16:16
 */
@Service
public class UserInfoServiceImpl extends ServiceImpl<IUserInfoMapper, UserInfo> implements IUserInfoService {
    @Override
    public UserInfo queryByUsername(String username) {
        // select id,username,email,nick_name from user_info where username = ?
        // 创建条件构造器
        LambdaQueryChainWrapper<UserInfo> wrapper
                = new LambdaQueryChainWrapper<>(this.getBaseMapper());
        // 构建条件，并获取查询结果
        UserInfo userInfo = wrapper.eq(UserInfo::getUsername, username)
                .eq(UserInfo::getDeleted, 0)
                .select(UserInfo::getId, UserInfo::getUsername,UserInfo::getPassword, UserInfo::getEmail, UserInfo::getNickName)
                .one();
        return userInfo;
    }

    @Override
    public List<UserInfo> queryByCreateTimeAndStatus(LocalDateTime start, LocalDateTime end, Integer status) {
        // 创建条件构造构造器
        LambdaQueryChainWrapper<UserInfo> wrapper
                = new LambdaQueryChainWrapper<>(this.getBaseMapper());
        // 构建条件，并获取查询结果
        List<UserInfo> list = wrapper.between(UserInfo::getCreateTime, start, end)
                .eq(UserInfo::getStatus, status)
                .list();
        return list;
    }
}
